<template>
  <div>
    <pub-header title="修改运力"></pub-header>
    <group style="margin-top: 0.2rem;">
      <x-input title="运力简称" v-model="formItem.nick_name" class="weui-vcode" placeholder="店铺名或公司名等"></x-input>
    </group>
    <div style="padding: 0.65rem 0.2rem;">
      <x-button type="primary" :show-loading="loading" @click.native="handleSub" action-type="button">确认</x-button>
    </div>
  </div>
</template>
<script>
  import PubHeader from '../../components/PubHeader.vue'
  export default{

    components: {
      PubHeader
    },
    data() {
      return {
        formItem: {
          uid: this.$store.state.userInfo.uid,
          nick_name: '',
          client: $config.client_type,
          device: $config.device_type,
          token: this.$store.state.userInfo.token
        },
        loading: false
      }
    },
    methods: {
      handleSub() {
        if(!this.formItem.nick_name) {
          this.$vux.toast.text('请输入您的简称', 'middle')
          return false
        }
        this.loading = true
        this.$http.post($config.host + '/api/Userinfo/changeNickname', qs.stringify(this.formItem)).then(res => {
          const { code, msg } = res.data
          this.loading = false
          if(code == 1) {
            this.$vux.toast.text('修改成功', 'middle')
            this.$router.go(-1)
          } else {
            this.$vux.toast.text(msg, 'middle')
          }
        }).catch(err => {
          this.loading = false
          this.$vux.toast.text($config.errMsg, 'middle')
        })
      }
    }
  }
</script>
